﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="EditEvent.aspx.cs" Inherits="LizzabethBrownRealEstate.Views.Admin.EditEvent"  %>
<%@ Import Namespace="LizzabethBrownRealEstate.Models" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
    <script type="text/javascript">
        $(document).ready(function(){
            $('#Title').focus();
            $('#EventStartDate').attachDatepicker(); 
            
            $("#frmNewEvent").validate({
           rules: {
             Title: "required",
             EventStart: "required",
             EventEnd: "required",
             StartHour: "required",
             StartMinute: "required",
             EndHour: "required",
             EndMinute: "required"
           },
           errorLabelContainer:"#frmEventErr",
           messages: {
             Title: "Please enter a title.",
             EventStart: "Please enter a start date.",
             EventEnd: "Please enter an end date.",
             EndHour: "Please enter an end hour.",
             EndMinute: "Please enter an end minute."
           }
        });
        
    });
    </script>
</asp:Content>
           
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <% LBRDataContext dc = new LBRDataContext();  %>
    <% Event e = dc.GetEvent(int.Parse(ViewData["EventId"].ToString())); %>
    <% if (e == null) e = new Event();  %>
    <% object vals = new {id = e.EventId };  %>
    <% 
        List<String> l = new List<String>(); 
        DateTime t = new DateTime(1900, 1, 1, 0, 0, 0);
        for (int i = 0; i < (24 * 4); i++)
        {
            l.Add(t.ToShortTimeString());
            t = t.AddMinutes(15);
        }  
     %>
                                 
    <div class="contentDiv" style="margin-left:20%">
    <form method="post" id="frmNewEvent" enctype="multipart/form-data" action="<%=  Url.Action("SaveOrUpdateEvent", "Admin", vals ) %>" >
        
            <fieldset id="fldRegister" style="width:450px;display:block;">
                <legend><%= e.EventId == null ? "New" : "Edit" %> Event</legend>
                <table>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label">Title:&nbsp;</label></td>
                        <td class="addPropertyField" colspan="3"><%= Html.TextBox("Title", e.Title, new {style="width: 330px;" })%></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Start">Date:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("EventStartDate", (e.EventStart.HasValue) ? e.EventStart.Value.ToShortDateString() : "", new { style = "width: 80px;" })%></td>
                        <td class="addPropertyField">
                            <label class="label">Start:</label>
                             <% object selstart = "9:00 AM"; 
                                 if (e.EventStart.HasValue) 
                                     selstart = e.EventStart.Value.ToShortTimeString(); 
                             %>
                             <%= Html.DropDownList("EventStartTime", new SelectList(l, selstart))%>
                        </td>
                        <td class="addPropertyField">
                            <label class="label">End:</label>
                            <% object selend = "9:00 AM"; 
                                if (e.EventEnd.HasValue) 
                                    selend = e.EventEnd.Value.ToShortTimeString(); 
                            %>
                            <%= Html.DropDownList("EventEndTime", new SelectList(l, selend))%>   
                        </td>
                    </tr>                                     
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Phone">Description:&nbsp;</label></td>
                        <td class="addPropertyField" colspan="3"><%= Html.TextArea("Description", e.Description, new { style = "width: 330px;" })%></td>
                    </tr>
                    <tr>
                        <td colspan="4"><div id="frmEventErr" class="ValidateErrorContainer"></div></td>
                    </tr>
                </table>
            </fieldset>
            <% if (Roles.IsUserInRole("Administrator"))
               { %>
            <div style="margin-top:15px; margin-bottom:15px">
                <%= Html.Hidden("CreateDate", DateTime.Now)%>
                <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
                <button onclick="window.location='../Admin.ashx/EventList'; return false;">Cancel</button>
            </div>
            <%} %>
        </form>
    </div>
</asp:Content>
